home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Think Class Libraries / WASTE TCL 1.8 / WASTE VA / Source / CApp.cp < prev    next >
Encoding:
Text File  |  1995-11-12  |  5.7 KB  |  218 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CApp.cp
  3.  
  4.                 My Application Class
  5.     
  6.     Copyright Â© 1995 Dan Crevier. All rights reserved.
  7.  
  8.     Generated by Visual Architectâ„¢ 9:19 AM Mon, Nov 6, 1995
  9.  
  10.     This file is only generated once. You can modify it by filling
  11.     in the placeholder methods and adding any new methods you wish.
  12.  
  13.     If you change the name of the application, a fresh version of this
  14.     file will be generated. If you have made any changes to the file
  15.     with the old name, you will have to copy those changes to the new
  16.     file by hand.
  17.  
  18.  ******************************************************************************/
  19.  
  20. #include "CApp.h"
  21.  
  22. #include <CDialog.h>
  23. #include <TCLForceReferences.h>
  24.  
  25. //#include "AppCommands.h"            // Remove comments if DoCommand overridden
  26.  
  27. #include "CWASTEText.h"
  28. #include "CWASTEDlgText.h"
  29.  
  30. #ifndef __SCRIPT__
  31. #include <Script.h>
  32. #endif
  33.  
  34. #include "CTSMSwitchboard.h"
  35. #include "CTSMDesktop.h"
  36.  
  37. #include <Drag.h>
  38.  
  39. static Boolean    DragAndDropAvailable(void);
  40. Boolean gHasDragAndDrop = false;
  41.  
  42. static Boolean    TSMAvailable(void);
  43.  
  44. extern CDesktop *gDesktop;
  45.  
  46. short gUsingTSM = false;
  47.  
  48. TCL_DEFINE_CLASS_M1(CApp, x_CApp);
  49.  
  50. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  51.  
  52. /******************************************************************************
  53.  CApp
  54.  
  55.         Constructor added by Dan Crevier
  56.  
  57.  ******************************************************************************/
  58.  
  59. CApp::CApp(void)
  60. {
  61.     gUsingTSM = TSMAvailable() && (InitTSMAwareApplication()==noErr);
  62.  
  63.     gHasDragAndDrop = DragAndDropAvailable();
  64. }
  65.  
  66. /******************************************************************************
  67.  ICApp
  68.  
  69.         Initialize an Application.
  70.  
  71.  ******************************************************************************/
  72.  
  73. void    CApp::ICApp()
  74.  
  75. {
  76.         // The values below are:
  77.         //
  78.         //     extraMasters        - The number of additional master pointer blocks
  79.         //                          to be allocated.
  80.         //     aRainyDayFund        - The total amount of reserved memory. When
  81.         //                          allocation digs into the rainy day fund, the
  82.         //                          user is notified that memory is low. Set this
  83.         //                          value to the sum of aCriticalBalance plus
  84.         //                          aToolboxBalance plus a fudge for user warning.
  85.         //     aCriticalBalance    - The part of the rainy day fund reserved for
  86.         //                          critical operations, like Save or Quit. Set
  87.         //                          this value to the memory needed for the largest
  88.         //                          possible Save plus aToolboxBalance. This
  89.         //                          memory will only be used if SetCriticalOperation()
  90.         //                          is set TRUE or if RequestMemory()/SetAllocation()
  91.         //                          is set FALSE (kAllocCantFail).
  92.         //     aToolboxBalance    - The part of the rainy day fund reserved for
  93.         //                          ToolBox bozos that bomb if a memory request fails.
  94.         //                          This memory is used unless RequestMemory()/
  95.         //                          SetAllocation() is set TRUE (kAllocCanFail).
  96.         //                          Almost all TCL memory allocation is done with
  97.         //                          kAllocCanFail, and yours should be, too. The
  98.         //                          default 2K is probably enough.
  99.  
  100.     Ix_CApp(4, 24000L, 20480L, 2048L);
  101.     
  102.         // Initialize your own application data here.
  103.  
  104. }
  105.  
  106.  
  107. /******************************************************************************
  108.  ~CApp
  109.  
  110.         Destruct an Application.
  111.  
  112.  ******************************************************************************/
  113.  
  114. CApp::~CApp()
  115. {
  116.     if (gUsingTSM) CloseTSMAwareApplication();
  117. }
  118.  
  119. /******************************************************************************
  120.  ForceClassReferences    {OVERRIDE}
  121.  
  122.     Reference classes that do object I/O or are created only
  123.     by new_by_name.
  124.  ******************************************************************************/
  125.  
  126. void CApp::ForceClassReferences(void)
  127.  
  128. {
  129.     x_CApp::ForceClassReferences();
  130.     
  131.         // Insert your own class references here
  132.         // by calling TCL_FORCE_REFERENCE for each class
  133.         // See x_CApp.cp
  134.     
  135.     TCL_FORCE_REFERENCE(CWASTEText);
  136.     TCL_FORCE_REFERENCE(CWASTEDlgText);
  137.     
  138. }
  139.  
  140.  
  141. /**** C O M M A N D   M E T H O D S ****/
  142.  
  143.  
  144. /******************************************************************************
  145.  DoCommand    {OVERRIDE}
  146.  
  147.     Handle application commands
  148.  ******************************************************************************/
  149.  
  150. void CApp::DoCommand(long theCommand)
  151.  
  152. {
  153.     switch (theCommand)
  154.     {
  155.  
  156.             // Insert your command cases here
  157.  
  158.         default:
  159.             x_CApp::DoCommand(theCommand);
  160.             break;
  161.     }
  162. }
  163.  
  164.  
  165. /******************************************************************************
  166.  GetDocTypeFromDialog
  167.  
  168.     Get the document type from the dialog. If you have multiple
  169.     document types, you must override this function to extract
  170.     the type from the dialog state. (The dialog has been executed
  171.     and OK'd by the user.) If you do not have multiple document
  172.     types, you can remove this function.
  173.  ******************************************************************************/
  174.  
  175. OSType CApp::GetDocTypeFromDialog(CDialogDirector *dialog)
  176.  
  177. {
  178.     return 0;
  179. }
  180.  
  181. // make TSMSwitchboard
  182. void CApp::MakeSwitchboard( void)
  183. {
  184.     if (gSystem.hasAppleEvents && gUsingTSM)
  185.     {
  186.         FailOSErr(WEInstallTSMHandlers());
  187.     }
  188.     itsSwitchboard = (CSwitchboard *)new CTSMSwitchboard();
  189.     itsSwitchboard->InitAppleEvents();
  190. }
  191.  
  192. // make TSMDesktop
  193. void CApp::MakeDesktop(void)
  194. {
  195.     gDesktop = (CDesktop *)new CTSMDesktop();
  196. }
  197.  
  198. static Boolean TSMAvailable(void)
  199. {
  200.     long    response;
  201.     
  202.     return (Gestalt(gestaltTSMgrVersion, &response)==noErr);
  203. }
  204.  
  205. /******************************************************************************
  206.  DragAndDropAvailable - returns true if drag and drop is available
  207.  ******************************************************************************/
  208.  
  209. static Boolean DragAndDropAvailable(void)
  210. {
  211.     long response;
  212.  
  213.     if (Gestalt(gestaltDragMgrAttr, &response) != noErr) return false;
  214.     if ((response & (1 << gestaltDragMgrPresent)) == 0) return false;
  215.     if ((Ptr)InstallTrackingHandler == 0) return false;
  216.     return true;
  217. }
  218.